import java.awt.desktop.SystemEventListener;
import java.util.Scanner;

public class J20241213 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        int[] arr1 = new int[9999];
        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = -1;
        }
        int maxId = 0;
        int minId = 0;
        int x = 0,y = 0;
        boolean again = false;
        String[] strings = new String[999];
        for (int i = 0; i < n; i++) {
            String idstring = scanner.nextLine();
            strings = idstring.split(" ");
            for (String idString : strings) {
                int id = Integer.parseInt(idString);
                if(arr1[id] == -1){
                    arr1[id] = 1;
                    if(maxId < id){
                        maxId = id;
                    }
                    if(minId > id){
                        minId = id;
                    }
                }else{

                    x = id;
                }
            }
        }


        for (int i = minId; i < maxId; i++) {
            if(arr1[i] == -1){
                y = i;
            }
        }
        System.out.print(x + " ");
        System.out.println(y);

    }
}